const inquirer = require("inquirer");

// 模板
const templates = [
  {
    name: "node 项目",
    git: "https://gitee.com/xtang-cli-templates/node.git",
  },
  {
    name: "webpack 项目",
    git: "https://gitee.com/xtang-cli-templates/webpack.git",
  },
  {
    name: "Vue3 项目",
    git: "https://gitee.com/xtang-cli-templates/vue.git",
  },
  {
    name: "Demo 项目",
    git: "https://gitee.com/xtang-cli-templates/demo.git",
  },
  {
    name: "代码规范",
    git: "https://gitee.com/xtang-cli-templates/lint.git",
  },
];

// 问题
const questions = [
  {
    type: "list",
    name: "template",
    message: "请选择要拉取一个模板",
    choices: templates.map((i) => i.name),
    default: "",
  },
];

// 提问问题
const selectTemplate = async () => {
  try {
    const { template } = await inquirer.prompt(questions);
    const gitUrl = templates.find((i) => i.name === template)?.git;
    return { template, gitUrl };
  } catch (err) {
    Promise.reject("取消操作");
  }
};

module.exports = selectTemplate;
